<?php

function print_requests(){ ?>

<?php 
	global $db;
	$orders = $db->get_all_requests();
	if ($orders):
?>
	
		
			<table id="order_table" cellspacing="0" cellpadding="0"><!-- Table -->
				<thead>
					<tr class="theader">
						<th style="width:40px">N.</th>
						<th>Name</th>
						<th>Recapiti</th>
						<th>Email</th>
						<th>Città</th>
						<th>Ulteriori richieste</th>
						<th>Data</th>
						<th>Libri</th>
						<th>Operazioni</th>
						

					</tr>
				</thead>
				
				<tbody>
	<?php $i = 0; setlocale(LC_TIME, "it_IT.utf8");
	
	
		 foreach ($orders as $order):
				extract($order);
				
				
				
				
				if (strlen( $additional ) > 10){
					$short_additional = substr($additional, 0,50)."... ";
					$short_additional.="<a href='javascript:return false;' class='more'>Altro</a>";
					$short_additional.="<div style='display:none' class='additional-fulltext'>$additional</div>";
				}
				else 
					$short_additional = $additional;
	 ?>				
					<tr <?php if($i % 2) { echo "class='alt'" ; };?>>
						<td ><?=$id?></td>
						<td class='name'><?=$name?> <?=$surname?></td>
						<td><?=$phone?><br><?=$mobile?></td>
						<td title="<?=$email?>"><?=$email?></td>
						<td><?=$city?> <?=$cap?><br><?=$address?></td>
						<td><?=$short_additional?></td>
						<td><?=strftime("%a %e %b %y" , strtotime($time))?></td>
						<td><?=count(json_decode($book_list, TRUE))?>
								<br><a class="view-books" href="javascript:return false;">Visualizza </a>
						
						
						</td>						
						
						<td><a id="complete" class="operation" href="javascript:return false;">Completa</a><br>
							<a id="delete" class="operation" href="javascript:return false;">Elimina</a><br>
							</td>
						<input class="request_id" id='<?=$id?>' type="hidden" value="<?=$id?>" />
						
					</tr>
				
					<tr style="display: none">
						<td   colspan="8" style="padding-left: 100px;">
							<table class="admin-book-list">
							<thead>
								<tr class="theader">
									<th>Titolo</th>
									<th>Autore</th>
									<th>Editore</th>
									<th>EAN</th>
									<th>N.Copie</th>
								</tr>
							</thead>
							<tbody >
							<?php 
							$books = json_decode($book_list , TRUE);
							foreach ($books as $b):
								$book = $db->get_book($b['id']);
							?>
							<tr>
								<td><?=$book['title']?></td>
								<td><?=$book['author']?></td>
								<td><?=$book['publisher']?></td>
								<td><?=$book['EAN']?></td>
								<td><?=$b['num_copies']?></td>
							</tr>
							
							<?php endforeach;?>
							</tbody>
							
						</table>
						</td>
					</tr>
				
					
<?php	$i++;
		endforeach; ?>
		
		</tbody>
			</table>
		</div>
		
	</div>
<?php 
	
	else: 
		echo "Nessuna richiesta in sospeso";
	endif;
}
?>